package com.wgo.precise.client.ui.controller.exceptions;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;

import com.wgo.precise.client.ui.controller.ModelStatus;
import com.wgo.precise.client.ui.controller.RequirementPlugin;

/**
 * 
 * @author Petter L. H. Eide
 * @version $Id: RematoClientException.java,v 1.2 2006-03-07 19:45:51 petterei Exp $
 */
public class RematoClientException extends RuntimeException {

	private static final long serialVersionUID = -6719231831114062653L;
	private IStatus status = null;
	
	public RematoClientException() {
        super();
    }

    public RematoClientException(String arg0) {
    	super(arg0);
    	//        this(new Status(IStatus.ERROR, Registry.PLUGIN_ID, 0, arg0, null)) ;
    }

    public RematoClientException(IStatus status) {
        super(status.getMessage(), status.getException());
        init(status);
    }
    
    public RematoClientException(String arg0, Throwable arg1) {
    	this(new ModelStatus(IStatus.ERROR, arg0, arg1));
    }

    public RematoClientException(Throwable e) {
        this(new ModelStatus(IStatus.ERROR, e.getMessage(), e));
    }

    private void init(IStatus initialStatus) {
    	this.status = initialStatus;
        if (status.getException() == null) {
            status = new Status (status.getSeverity(),status.getPlugin(), status.getCode(), status.getMessage(), this);
        } else {
            super.setStackTrace(status.getException().getStackTrace());
        }
        errorMessage("Error", "Exception thrown: " + status.getMessage(), status);
//        log(status);
    }

    private static void errorMessage(String dialogTitle, String message, IStatus status) {
    	if (! RequirementPlugin.getInstance().getWorkbench().isClosing()) {
    		ErrorDialog.openError(null, dialogTitle, message, status);
    	}
    }

    public void log () {
        RequirementPlugin.getInstance().getLog().log( status );
    }
    public IStatus getStatus() {
    	return status;
    }
}
/**
 * 
 * Changelog:
 * 
 * $Log: RematoClientException.java,v $
 * Revision 1.2  2006-03-07 19:45:51  petterei
 * added URL as property type
 *
 * Revision 1.1  2006-01-23 19:58:38  petterei
 * initial commit for client, fitting the alternative session implementation
 *
 * Revision 1.4  2005-12-21 20:03:07  petterei
 * added logic to avoid and handle exceptions thrown from DomainSession and server
 *
 * Revision 1.3  2005-12-13 12:10:54  petterei
 * refactorin + bugfix
 *
 * Revision 1.2  2005/10/02 21:31:16  petterei
 * client with new domain model
 *
 * Revision 1.1  2005/09/27 21:05:53  petterei
 * *** empty log message ***
 *
 * Revision 1.3  2005/09/27 17:06:20  petterei
 * *** empty log message ***
 *
 * Revision 1.2  2005/08/23 06:40:59  peide3
 * *** empty log message ***
 *
 * Revision 1.1  2005/07/31 22:55:10  petterei
 * initial commit
 *
 * Revision 1.1  2005/07/14 06:38:37  peide3
 * Implemented functionality 'update' nodes and create project.
 *
 */
